<template>
  <el-container>
    <el-header>
      <h3>学员评价箱</h3>
    </el-header>
    <el-main>
      <el-form :inline="true" ref="form" :model="form">
        <el-form-item prop="query_field">
          <el-input v-model="form.query_field" placeholder="输入学员名称或手机号码" suffix-icon="el-icon-search" @keyup.enter.native="search"></el-input>
        </el-form-item>
        <el-form-item label="星级筛选:" prop="score">
          <el-select v-model="form.score">
            <el-option
              v-for="item in scoreList"
              :value="item.id"
              :key="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="教练选择:" prop="coach_id">
          <el-select v-model="form.coach_id">
            <el-option
              v-for="item in coachList"
              :key="item.id"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click.prevent="search">查询</el-button>
          <el-button type="primary" icon="el-icon-refresh" @click.prevent="reset('form')">重置</el-button>
        </el-form-item>
      </el-form>
      <div class="main">
        <el-card
          v-for="item in tableData"
        >
          <div class="evaluate_list">
            <div class="float_list">
              <el-avatar :src="item.student_avatar" :size="50"></el-avatar>
            </div>
            <div class="float_list">
              <h3>{{item.student_name}}</h3>
            </div>
            <div class="float_list">
              <h3>{{item.student_mobile}}</h3>
            </div>
            <div class="float_list">
              <el-row>
                <span>评价星级:</span>
                <el-rate
                  style="display: inline;"
                  v-model="item.score"
                  disabled
                  show-score
                  text-color="#ff9900"
                >
                </el-rate>
              </el-row>
            </div>
            <div class="content">
              <el-input type="textarea" v-model="item.content" :rows="5"></el-input>
            </div>
            <div class="coach_content">
              <el-row>
                <span>所属教练: <b>{{item.coach_name}}</b></span>
              </el-row>
              <el-row>
                <span>评价时间: <b>{{item.comment_time}}</b></span>
              </el-row>
            </div>
          </div>
        </el-card>
      </div>
    </el-main>
    <el-footer>
      <el-pagination
        background
        layout="prev, pager, next, total"
        :total="total"
        :current-page="page"
        :page-size="pageSize"
        @current-change="changePage"
      ></el-pagination>
    </el-footer>
  </el-container>
</template>

<script>
    import {getCoachList} from '@/api/coach'
    import {evaluateList} from '@/api/school'
    export default {
        name: "evaluateList",
        data () {
            return {
                tableData: [],
                total: 0,
                page: 1,
                pageSize: 10,
                form: {
                    query_field: '',
                    score: 0,
                    coach_id: 0,
                },
                scoreList: [
                    {id: 0, name: '全部'},
                    {id: 1, name: '1星'},
                    {id: 2, name: '2星'},
                    {id: 3, name: '3星'},
                    {id: 4, name: '4星'},
                    {id: 5, name: '5星'},
                ],
                coachList: [
                    {id: 0, name: '全部'},
                ]
            };
        },
        methods: {
            changePage(currentValue) {
                var params = {
                    coach_id: this.form.coach_id,
                    score: this.form.score,
                    page: currentValue,
                    pageSize: this.pageSize
                };
                if (this.form.query_field.trim().length != 0) {
                    params.query_field = this.form.query_field.trim();
                }
                var loading = this.$loading({
                    lock: true,
                    text: '加载中',
                    target: document.querySelector('.main')
                });

                evaluateList(params).then(response => {
                    this.tableData = response.data.list;
                    this.page = Number(response.data.paginate.current);
                    this.pageSize = Number(response.data.paginate.pageSize);
                    this.total = Number(response.data.paginate.total);
                    loading.close();
                });
            },
            reset(ref) {
                this.$refs[ref].resetFields();
            },
            search() {
                var params = {
                    coach_id: this.form.coach_id,
                    score: this.form.score
                };

                if (this.form.query_field.trim().length != 0) {
                    params.query_field = this.form.query_field.trim();
                }

                var loading = this.$loading({
                    lock: true,
                    text: '加载中',
                    target: document.querySelector('.main')
                });

                evaluateList(params).then(response => {
                    this.tableData = response.data.list;
                    this.page = response.data.paginate.current;
                    this.pageSize = response.data.paginate.pageSize;
                    this.total = response.data.paginate.total;
                    loading.close();
                });
            }
        },
        mounted() {
            var loading = this.$loading({
                lock: true,
                text: '加载中',
                target: document.querySelector('.main')
            });

            getCoachList().then(response => {
              response.data.forEach(row => {
                  this.coachList.push(row);
              });

              evaluateList({}).then(response => {
                  this.tableData = response.data.list;
                  this.page = response.data.paginate.current;
                  this.pageSize = response.data.paginate.pageSize;
                  this.total = response.data.paginate.total;
                  loading.close();
              })
            }).catch( err => {

            })
        }
    }
</script>

<style scoped>
  .el-container{
    width: 90%;
    max-width: 100%;
    overflow: hidden;
    border: 1px solid #F2F6FC;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
    margin: 10px auto;
  }

  .el-header {
    text-align: center;
  }
  .el-header h3 {
    font-size: 20px;
    height: 20px;
    line-height: 20px;
  }
  .el-main {
    width: 90%;
    max-width: 100%;
    overflow: hidden;
    border: 1px solid #F2F6FC;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
    margin: 5px auto;
  }
  .el-footer {
    text-align: center;
  }

  .float_list {
    float: left;
    width: 25%;
  }

  .float_list h3 {
    font-weight: normal;
    color: gray;
  }
  .float_list .el-row {
    display: inline-block;
    height: 58px;
    line-height: 58px;
  }
  .content {
    clear: both;
  }
  .coach_content {
    margin-left: 55%;
    width: 45%;
    text-align: right;
  }
  .coach_content .el-row {
    display: inline-block;
    margin-top: 10px;
    height: 20px;
    line-height: 20px;
    margin-left: 10px;
  }
</style>
